﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge_zxing;
using Supermarket;
using System.Data.SqlClient;
using XLSupermarket.Cashier.VIP;
using XLSupermarket.Account.ChangePassword;
using System.Drawing.Printing;

namespace XLSupermarket.Cashier
{
    public partial class Cashier : Form
    {
        public static string UserName;//收银员姓名
        double Sum_money = 0.00;//原价
        double PSum_money = 0.00;//折后价
        bool isVIP = false;//是否为会员
        public static string VIP_Name = "";//会员姓名
        public static int VIP_Num = 0;//会员编号
        double z_money = 0.00;//找零
        int Sum_Count = 0;//数量总和
        public static string Dingdan = DateTime.Now.ToString("yyyyMMddHHmmss");//订单编号 年月日时分秒组成
        string orderNumber = "";
        string YiFu = "";
        public Cashier()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 店长判断
        /// </summary>
        /// <returns></returns>
        private bool Rank()
        {

            String sql = "select * from EP_information EI , EP_Number EN where EI.EP_ID=EN.EP_ID and Staff_Name='店长' and EN.UserName='" + LoginForm.UserName_Value + "'";
            if (DBHelper.FillData(sql).Rows.Count > 0) return true;
            else return false;
        }
        /// <summary>
        /// 选择使用textbox_1的条码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                bool isGoods = true;
                int num;
                double money, Price;
                string bar_code_copy = "";
                string sql = "select GW.Bar_code 条形码,Trade_Name 商品名称,Gw.Specifications 规格,MI.Retail_Price 单价, COUNT(GW.Bar_code) 数量,MI.Discount 折扣, MI.Retail_Price* MI.Discount 折扣价,MI.Retail_Price 小计,GW.DateOfManufacture 生产日期, GW.QualityGuaranteePeriod 保质期, DATEADD(DAY, GW.QualityGuaranteePeriod, GW.DateOfManufacture) 到期日期,SL.Supplier_Name 供应商名称, GW.Other 备注 from Goods_Warehousing GW,Supplier SL, Merchandise_inventory MI where GW.Bar_code = MI.Bar_code and SL.Supplier_ID = GW.Supplier_ID and GW.Bar_code='" + textBox1.Text + "' GROUP BY GW.Bar_code ,Trade_Name,Gw.Specifications ,MI.Retail_Price  ,MI.Discount ,MI.Retail_Price* MI.Discount ,GW.DateOfManufacture ,GW.QualityGuaranteePeriod ,DATEADD(DAY, GW.QualityGuaranteePeriod, GW.DateOfManufacture) ,SL.Supplier_Name ,GW.Other ";
                SqlDataReader sdr = DBHelper.Readers(sql);
                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    bar_code_copy = listView1.Items[i].SubItems[0].Text;//获取listView的条形码列表遍历
                    if (textBox1.Text.Trim() == bar_code_copy)//判断条形码是否存在
                    {
                        num = int.Parse(listView1.Items[i].SubItems[4].Text);//数量
                        money = double.Parse(listView1.Items[i].SubItems[3].Text);//单价
                        //Price = double.Parse(listView1.Items[i].SubItems[7].Text);//小计
                        Price = num * money;
                        num++;//数量+1
                        Price += money;//小计+单价
                        listView1.Items[i].SubItems[4].Text = num.ToString();//数量
                        listView1.Items[i].SubItems[7].Text = Price.ToString();//折后价
                        isGoods = false;//已经存在商品，不需要添加
                        break;
                    }
                }
                if (isGoods)
                {
                    while (sdr.Read())
                    {
                        string bar_code = sdr[0].ToString();//条形码
                        string trade_name = sdr[1].ToString();//商品名称
                        string Specifications = sdr[2].ToString();//规格
                        string Retail_Price = sdr[3].ToString();//单价
                        string Number = sdr[4].ToString();//数量
                        string Discount = sdr[5].ToString();//折扣
                        string discount_price = sdr[6].ToString();//折扣价
                        string SumPrice = sdr[7].ToString();//小计
                        string DateOfManufacture = sdr[8].ToString();//生产日期
                        string QualityGuaranteePeriod = sdr[9].ToString();//保质期
                        string Due_date = sdr[10].ToString();//到期日期
                        string Supplier_Name = sdr[11].ToString();//供货商名称
                        string Other = sdr[12].ToString();//备注

                        ListViewItem item1 = new ListViewItem(bar_code);//条形码
                        item1.SubItems.Add(trade_name);//商品名称
                        item1.SubItems.Add(Specifications);//规格
                        item1.SubItems.Add(Retail_Price);//单价
                        item1.SubItems.Add("1");//数量
                        item1.SubItems.Add(Discount);//折扣
                        item1.SubItems.Add(discount_price);//折扣价
                        item1.SubItems.Add(SumPrice);//小计
                        item1.SubItems.Add(DateOfManufacture);//生产日期
                        item1.SubItems.Add(QualityGuaranteePeriod);//保质期
                        item1.SubItems.Add(Due_date);//到期日期
                        item1.SubItems.Add(Supplier_Name);//供货商名称
                        item1.SubItems.Add(Other);//备注
                        listView1.Items.Add(item1);
                    }
                }
                textBox1.Text = "";//条形码输入框清空
                sdr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("您的条码输入有误，请检查是否输入错误！\t如果多次错误，请联系管理员！\t" + ex.Message, "提示");
            }
            finally
            {
                F_5();
            }
        }
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("您确定退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
                System.Environment.Exit(0);
            }
        }
        /// <summary>
        /// 加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cashier_Load(object sender, EventArgs e)
        {
            try { 
            textBox2.ReadOnly = true;
            textBox2.Text = "0.00";
            textBox5.ReadOnly = true;
            textBox5.Text = "0.00";
            textBox7.ReadOnly = true;
            textBox7.Text = "0.00";
            timer1.Start();
            //对于dataGridViewl的列表进行自动排版，适配窗体大小
            //dataGridView1.Dock = DockStyle.Fill;
            //dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            UserName = LoginForm.UserName_Value;
            string sql = "select EP_Name from EP_information ei,EP_Number en where ei.EP_ID = en.EP_ID and UserName = '" + UserName + "'";
            DataTable dt = DBHelper.FillData(sql);//查看名字
            string EP_Name = dt.Rows[0][0].ToString();
            Lable_CashierName.Text = EP_Name;
            if (Rank()) BT_SUP.Show();
            else BT_SUP.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 退出前的确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cashier_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Cancel) e.Cancel = true;
        }
        /// <summary>
        /// 扫描按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            try { 
            Form1 AF = new Form1();
            DialogResult result = AF.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBox1.Text = AF.reisbn;
            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 实收文本框值发生改变后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            F_5();
        }
        /// <summary>
        /// 判断是否为会员
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Text_VIPNumber_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string sel = "VIP_ID = '";
                if (Text_VIPNumber.Text.Length > 8)
                {
                    sel = "VIP_TEL='";
                }
                string sql = "select VIP_Name,VIP_ID from VIP_information where " + sel + Text_VIPNumber.Text + "' ";
                DataTable dt = DBHelper.FillData(sql);
                if (dt.Rows.Count > 0)
                {
                    string path = dt.Rows[0]["VIP_Name"].ToString();
                    VIP_Name = path;
                    VIP_Num = int.Parse(dt.Rows[0]["VIP_ID"].ToString());
                    isVIP = true;
                    Lable_VIPName.Text = VIP_Name;
                    label5.Text = PSum_money.ToString("F2");
                }
                else
                {
                    label5.Text = Sum_money.ToString("F2");
                    isVIP = false;
                    Lable_VIPName.Text = "";
                }
                F_5();
            }
            catch (Exception ex) {
                MessageBox.Show("请检查您的输入！只能为编号或手机号！");
            }
        }
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem selectedItem = this.listView1.SelectedItems[0];
                this.listView1.Items.Remove(selectedItem);
                F_5();
            }
            catch (Exception)
            {
                MessageBox.Show("您未选择到任何值！", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }
        private void 修改数量ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Text_UpNum.Text == "" || Text_UpNum.Text == "0")
                {
                    MessageBox.Show("请检查数量值！");
                    return;
                }
                string bar = listView1.SelectedItems[0].SubItems[0].Text;
                string sql = "select Quantity_Of_Goods from Goods_Shelves where Bar_code = '" + bar + "'";
                DataTable dt = DBHelper.FillData(sql);
                int num_2 = int.Parse(dt.Rows[0][0].ToString());//货架现存数量
                if (int.Parse(Text_UpNum.Text) > num_2)
                {
                    MessageBox.Show("您输入的商品数量已经大于货架现存数量\n如需购买大量商品请联系仓库管理人员", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                ListViewItem selectedItem = this.listView1.SelectedItems[0];
                selectedItem.SubItems[4].Text = Text_UpNum.Text;//数量
                Text_UpNum.Text = "";
                F_5();
                if (listView1.Items.Count <= 0)
                {
                    Clear();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("您未选择到任何值！", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void Clear()
        {
            label5.Text = "0.00";
            label7.Text = "0";
            textBox2.Text = "0.00";
            textBox3.Text = "0.00";
            textBox4.Text = "0.00";
            textBox5.Text = "0.00";
            textBox7.Text = "0.00";
            Text_VIPNumber.Text = "0";
        }
        private void F_5()
        {
            try
            {
                int count = 0;
                double Price, DPrice;
                Sum_Count = 0;
                Sum_money = 0.00;
                PSum_money = 0.00;
                bool result = true;
                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    int num = int.Parse(listView1.Items[i].SubItems[4].Text);//数量
                    string bar = listView1.Items[i].SubItems[0].Text;//Bar_code
                    string sql = "select Quantity_Of_Goods from Goods_Shelves where Bar_code = '" + bar + "'";
                    DataTable dt = DBHelper.FillData(sql);
                    int num_2 = int.Parse(dt.Rows[0][0].ToString());//货架现存数量
                    double money = double.Parse(listView1.Items[i].SubItems[3].Text);//单价
                    if (num > num_2)
                    {
                        MessageBox.Show("您输入的商品数量已经大于货架现存数量\n如需购买大量商品请联系仓库管理人员", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        continue;
                    }
                    Price = num * money;
                    listView1.Items[i].SubItems[4].Text = num.ToString();//数量
                    listView1.Items[i].SubItems[7].Text = Price.ToString();//折后价
                    count = int.Parse(listView1.Items[i].SubItems[4].Text);//单个商品数量
                    DPrice = double.Parse(listView1.Items[i].SubItems[6].Text);//商品折扣价
                    Sum_Count += count;//总数量
                    Sum_money += Price;//总价格
                    PSum_money += count * DPrice;
                    textBox2.Text = Sum_money.ToString("F2");//原价
                    textBox5.Text = PSum_money.ToString("F2");//折扣价
                    textBox7.Text = (PSum_money * 0.2).ToString("F2");
                    label5.Text = Sum_money.ToString("F2");
                    label7.Text = Sum_Count.ToString();
                    if (isVIP) label5.Text = PSum_money.ToString("F2");
                    double s_money = double.Parse(textBox3.Text);
                    z_money = s_money - Sum_money;
                    if (isVIP) z_money = s_money - PSum_money;
                    textBox4.Text = z_money.ToString("F2");
                    result = false;
                }
                if (result) Clear();
            }
            catch (Exception ex)
            {

            }
        }
        /// <summary>
        /// 结算功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            try { 
            if (double.Parse(textBox4.Text) < 0)
            {
                MessageBox.Show("您所支付的金额不足以完成此单操作！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            bool result_1 = false;
            bool result_2 = false;
            bool result_3 = false;
            Dingdan = label3.Text;//订单编号/Order_Number
            string sql_EP_ID = "select EP_ID from EP_Number where UserName='" + UserName + "'";
            DataTable dt = DBHelper.FillData(sql_EP_ID);//查看名字
            string Order_Number = Dingdan;
            int EP_ID = int.Parse(dt.Rows[0][0].ToString());
            string Cash_register_Method = "现金";
            int VIP_ID;
            double Add_Score;
            Double Receivables;
            double Paid_in_Amount = Double.Parse(textBox3.Text);
            Double Give_Change = Double.Parse(textBox4.Text);
            DateTime Time_Of_Sale = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            int Sales_Number = int.Parse(label7.Text);
            if (isVIP)
            {//会员
                Receivables = double.Parse(textBox5.Text);
                VIP_ID = int.Parse(Text_VIPNumber.Text);
                Add_Score = double.Parse(textBox7.Text);
                result_1 = JieSuan_VIP(Order_Number, EP_ID, Cash_register_Method, VIP_ID, Add_Score, Receivables, Paid_in_Amount, Give_Change, Time_Of_Sale, Sales_Number);
            }
            else
            {//非会员
                Receivables = double.Parse(textBox2.Text);
                result_1 = JieSuan_VIP(Order_Number, EP_ID, Cash_register_Method, Receivables, Paid_in_Amount, Give_Change, Time_Of_Sale, Sales_Number);
            }
            //订单详情表
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                string bar = listView1.Items[i].SubItems[0].Text;//Bar_code
                int num = int.Parse(listView1.Items[i].SubItems[4].Text);//Number
                double Price = double.Parse(listView1.Items[i].SubItems[3].Text);//Price
                string sql = string.Format("insert into Order_Details Values('{0}','{1}','{2}',{3})",
                    Dingdan, bar, num, Price);
                result_2 = DBHelper.Edit(sql) > 0 ? true : false;
                result_3 = JieSuan_KuCun(num, bar);
                if (result_2 == false || result_3 == false)
                {
                    MessageBox.Show("销售失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
            }
            if (result_1 && result_2 && result_3)
            {
                YiFu = textBox3.Text;
                MessageBox.Show("销售成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                listView1.Items.Clear();

                GetPrintStr();
                daying();
                Clear();
            }
            else
            {
                MessageBox.Show("销售失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 会员结算
        /// </summary>
        /// <param name="Order_Number">订单编号</param>
        /// <param name="EP_ID">收银员编号</param>
        /// <param name="Cash_register_Method">收银方式</param>
        /// <param name="VIP_ID">会员编号</param>
        /// <param name="Add_Score">获得积分</param>
        /// <param name="Receivables">应收额</param>
        /// <param name="Paid_in_Amount">实收额</param>
        /// <param name="Give_Change">找零</param>
        /// <param name="Time_Of_Sale">售出时间</param>
        /// <param name="Sales_Number">销售数量</param>
        private bool JieSuan_VIP(string Order_Number, int EP_ID, string Cash_register_Method, int VIP_ID, double Add_Score, Double Receivables, double Paid_in_Amount, Double Give_Change, DateTime Time_Of_Sale, int Sales_Number)
        {
            orderNumber = Order_Number;
            string sql = string.Format("insert into Sales_Order Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')",
               Order_Number, EP_ID, Cash_register_Method, VIP_Num, Add_Score, Receivables, Paid_in_Amount, Give_Change, Time_Of_Sale, Sales_Number);
            bool result = DBHelper.Edit(sql) > 0 ? true : false;
            if (result == false) return result;
            string sql_score = "select VIP_Score from VIP_information where  VIP_ID='" + VIP_Num + "'";
            double score = double.Parse(DBHelper.FillData(sql_score).Rows[0][0].ToString());
            score += Add_Score;
            string score_up = "update VIP_information set VIP_Score='" + score + "' where VIP_ID='" + VIP_Num + "'";
            result = DBHelper.Edit(score_up) > 0 ? true : false;
            return result;
        }
        /// <summary>
        /// 非会员结算(会员结算的重载)
        /// </summary>
        /// <param name="Order_Number">订单编号</param>
        /// <param name="EP_ID">收银员编号</param>
        /// <param name="Cash_register_Method">收银方式</param>
        /// <param name="Receivables">应收额</param>
        /// <param name="Paid_in_Amount">实收额</param>
        /// <param name="Give_Change">找零</param>
        /// <param name="Time_Of_Sale">售出时间</param>
        /// <param name="Sales_Number">销售数量</param>
        private bool JieSuan_VIP(string Order_Number, int EP_ID, string Cash_register_Method, Double Receivables, double Paid_in_Amount, Double Give_Change, DateTime Time_Of_Sale, int Sales_Number)
        {
            orderNumber = Order_Number;
            string sql = string.Format("insert into Sales_Order Values('{0}','{1}','{2}',NULL,NULL,'{3}','{4}','{5}','{6}','{7}')",
               Order_Number, EP_ID, Cash_register_Method, Receivables, Paid_in_Amount, Give_Change, Time_Of_Sale, Sales_Number);
            bool result = DBHelper.Edit(sql) > 0 ? true : false;
            return result;
        }
        /// <summary>
        /// 查看库存剩余是否足够货售卖
        /// </summary>
        /// <param name="num"></param>
        /// <param name="bar_code"></param>
        /// <returns></returns>
        private bool JieSuan_KuCun(int num, string bar_code)
        {
            string sql_1 = "select Quantity_Of_Goods from Goods_Shelves where Bar_code = '" + bar_code + "'";
            DataTable dt = DBHelper.FillData(sql_1);
            int num_2 = int.Parse(dt.Rows[0][0].ToString());//货架现存数量
            num = num_2 - num;
            if (num < 0)
            {
                MessageBox.Show("库存数量不足此次售卖！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            string sql = "update Goods_Shelves set Quantity_Of_Goods = '" + num + "' where Bar_code = '" + bar_code + "'";
            bool result = DBHelper.Edit(sql) > 0 ? true : false;
            return result;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label3.Text = DateTime.Now.ToString("yyyyMMddHHmmss");
        }
        /// <summary>
        /// 清空按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BT_Empty_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            Clear();
            F_5();
        }
        private void 添加会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_VIP av = new Add_VIP();
            av.ShowDialog();
        }
        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpPwd up = new UpPwd();
            up.ShowDialog();
        }
        private void 会员信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Select_VIP sv = new Select_VIP();
            sv.ShowDialog();
        }
        private void BT_SUP_Click(object sender, EventArgs e)
        {
            MainInterface.MainForm MainForm = new MainInterface.MainForm();
            this.Hide();
            MainForm.Show();
        }
        private void 信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Account.Information.seletInformationForm AISI = new Account.Information.seletInformationForm();
            AISI.ShowDialog();
        }
        private void 订单查询ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Order.Select_Order OS = new Order.Select_Order();
            OS.ShowDialog();
        }
        /// <summary>
        /// 打印
        /// </summary>
        /// <returns></returns>
        public string GetPrintStr()
        {
            DataTable dt = new DataTable();
            string sql = string.Format("select * from Order_Details od,Sales_Order so where so.Order_Number=od.Order_Number and od.Order_Number='{0}'", orderNumber);
            dt = DBHelper.FillData(sql);
            StringBuilder sb = new StringBuilder();
            string saleID = dt.Rows[0][1].ToString();
            decimal total = 0.00M;
            sb.Append("        \t    " + "湘龙超市" + "     \n");
            sb.Append("-----------------------------------------------------------------\n");
            sb.Append("日期:" + DateTime.Now.ToShortDateString() + "\t\t  " + "单号:" + orderNumber + "\n");
            sb.Append("-----------------------------------------------------------------\n");
            sb.Append("商品" + "\t\t  " + "类别" + "\t\t" + "数量" + "\t" + "单价" + "\n");
            string SQL = string.Format("select GW.Trade_Name,GT.GoodsType_Name,od.Number,od.Price from Order_Details od,Sales_Order so,Goods_Warehousing GW,Goods_Type GT where so.Order_Number=od.Order_Number and od.Bar_code = GW.Bar_code and GW.GoodsType_ID = GT.GoodsType_ID and od.Order_Number='{0}'", orderNumber);
            DataTable DT = new DataTable();
            DT = DBHelper.FillData(SQL);
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                sb.Append(DT.Rows[i][0].ToString() + "\t\t" + DT.Rows[i][1].ToString() + "\t" + DT.Rows[i][3].ToString() + "\t" + DT.Rows[i][2].ToString());
                total += decimal.Parse(DT.Rows[0][2].ToString());
                if (i != (DT.Rows.Count)) sb.Append("\n");
            }
            sb.Append("-----------------------------------------------------------------\n");
            sb.Append("数量: " + Sum_Count + " 合计:   " + PSum_money + "\n");
            sb.Append("付款: 现金" + " " + textBox3.Text);
            sb.Append("现金找零:" + " " + z_money + "\n");
            sb.Append("-----------------------------------------------------------------\n");
            sb.Append("地址：" + "湖南工程职业技术学院" + "\n");
            sb.Append("电话：" + "10010010010" + "    " + "0731-005050" + "\n\n");
            sb.Append("                 " + "谢谢惠顾！欢迎下次光临！" + "                    ");
            return sb.ToString();
        }
        private int getYc(double cm)
        {
            return (int)(cm / 25.4) * 100;
        }
        private void daying()
        {
            //打印预览   
            PrintPreviewDialog ppd = new PrintPreviewDialog();
            //设置边距
            Margins margin = new Margins(20, 20, 20, 20);
            pd.DefaultPageSettings.Margins = margin;
            ////纸张设置默认
            PaperSize pageSize = new PaperSize("First custom size", getYc(100), 600);
            pd.DefaultPageSettings.PaperSize = pageSize;
            //打印事件设置            
            pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            ppd.Document = pd;
            ppd.ShowDialog();
            try
            {
                pd.Print();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                pd.PrintController.OnEndPrint(pd, new PrintEventArgs());
            }
        }
        private void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            string sb = GetPrintStr();
            Font f = new Font("宋体", 8);
            e.Graphics.DrawString(sb, f, Brushes.Black, 10, 50);
        }

        private void 注销ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            LoginForm LF = new LoginForm();
            LF.Show();
            this.Hide();
        }
    }
}
